/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package datos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Jose
 */
public class RDMS {

    public static Connection GetConnection() {
        Connection coneccion;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            String servidor = "jdbc:mysql://localhost/shuckapp";
            String usuarioDB = "root";
            String passwordDB = "jmga1987";
            coneccion = DriverManager.getConnection(servidor, usuarioDB, passwordDB);
        } catch (Exception ex) {
            System.out.println(ex);
            coneccion = null;
        }
        return coneccion;
    }

    public static ResultSet consulta(String cadena, Connection c) {

        if (c == null) {
            return null;
        }
        try {

            Statement st = c.createStatement();
            ResultSet rs = st.executeQuery(cadena);
           
            return rs;
        } catch (SQLException ex) {
            Logger.getLogger(RDMS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public static int actualizar(String cadena, Connection conexion) {

        if (conexion == null)
            return 0;        
        
        try {

            Statement st = conexion.createStatement();
            return st.executeUpdate(cadena);

        } catch (SQLException ex) {
            Logger.getLogger(RDMS.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return 0;
    }
}
